feat(es/minifier): Implement safe property mangling for dynamically-accessed objects#11475
feat(es/minifier): Implement safe property mangling for dynamically-accessed objects#11475
Conversation
|
|
|
Binary Sizes
Commit: e55c951 |
|
@claude Add as many test cases as you can |
|
Claude finished @kdy1's task in 20m 58s —— View job Adding Test Cases for Safe Property Mangling
|
|
Claude finished @kdy1's task in 16m 53s —— View job Adding Execution Tests for Safe Property Mangling
Summary: Added 55 comprehensive execution tests for safe property mangling. These tests verify that the minified code produces the same runtime output as the original code. The tests cover a wide range of complex real-world scenarios:
All tests pass:
|
|
@claude fix CI |
|
Claude finished @kdy1's task in 3m 44s —— View job Fixing CI
Summary: Fixed the CI failure by inlining format arguments in |
|
@claude Fix CI |
|
Claude finished @kdy1's task in 51s —— View job Fixing CI
Summary: The CI failure is not a code issue in this PR. The failure is in the "Test node bindings - windows-latest" job due to a segmentation fault in the wasm-pack installer: This is a transient infrastructure issue with the wasm-pack installer on Windows. All other CI jobs are passing:
Recommendation: Please re-run the failed job "Test node bindings - windows-latest" manually. I don't have permission to trigger re-runs. This is a known intermittent issue with wasm-pack installation on Windows runners. |
|
Claude finished @kdy1's task in 26m 47s —— View job Fixing Visitor Definition Issue
Summary: Refactored the property mangling code to remove the custom Key changes:
View job · |
|
@claude Resolve merge conflicts |
|
Claude finished @kdy1's task —— View job Resolving Merge Conflicts
Summary: Resolved merge conflicts by rebasing the PR branch onto the latest |
…ccessed objects
When an object is accessed with a dynamic key (e.g., `obj[variable]`), only
its direct properties are now protected from mangling. Nested properties
that are always accessed with static keys can still be mangled safely.
For example, in:
```js
const sizes = { A4: { xwidth: '21cm' } };
console.log(sizes[paper].xwidth);
```
- `A4` will NOT be mangled (dynamic access via `sizes[paper]`)
- `xwidth` WILL be mangled (static access via `.xwidth`)
Note: Properties that are reserved DOM/JS environment properties (like
`width`, `height`, `inner`) are never mangled regardless of access pattern.
Closes #10332
Co-authored-by: Donny/강동윤 <[email protected]>
…gling Add 40+ test cases covering various scenarios for safe property mangling of dynamically-accessed objects, including: - Dynamic access with function call keys, template literals, binary expressions - Destructuring patterns with dynamic property sources - Computed property names in object literals - Array-like numeric access - Spread operators with dynamic objects - Prototype chain and inheritance scenarios - Event handler patterns - Factory and builder patterns - Module-like patterns with exports - Nested object access with mixed static/dynamic keys Also adds a new helper function `assert_props_preserved_and_mangled` for more robust testing that doesn't depend on exact variable naming order. Co-Authored-By: Claude Opus 4.5 <[email protected]>
…y mangling Add 55 execution tests that verify the minified code produces the same output as the original when property mangling is applied. These tests cover: - Basic/nested dynamic property access - For-in loops and Object.keys/entries iteration - Class static/instance properties with dynamic access - Object destructuring and spread operators - Template literal and computed property keys - State management patterns (Redux-like) - Event emitter patterns - i18n translation patterns - Plugin system and dependency injection - Factory and observable patterns - Query builder and middleware chains - Reducer patterns - Router and theme patterns - Configuration merging and feature flags - Shopping cart and user permissions scenarios - API response handlers and workflow engines - Graph traversal and pagination patterns - And many more complex real-world scenarios These tests ensure that property mangling with safe detection of dynamically accessed objects does not break runtime behavior. Co-authored-by: kdy1 <[email protected]>
… tests Inline format arguments to satisfy the clippy lint. Co-authored-by: Donny/강동윤 <[email protected]>
…ty mangling Remove `UnsafePropertyCollector` and `NestedUnsafePropertyCollector` structs that implemented the `Visit` trait. Instead, use helper functions to traverse the AST and collect unsafe properties, leveraging the pre-analyzed `ProgramData` from `analyze()`. The refactored code: - Uses `INDEXED_WITH_DYNAMIC_KEY` and `EXPORTED` flags from `VarUsageInfo` - Traverses var declarators to find object literals assigned to unsafe variables - Collects property names from those object literals as unmangleable Also updates the `object_spread_dynamic_access` test to reflect that spread sources are treated as potentially dynamically accessed (per the existing `UsageAnalyzer` behavior). Co-authored-by: Donny/강동윤 <[email protected]>
ffcc20a to
d13a4aa
Compare

Summary
Implement safe property mangling for dynamically-accessed objects. When an object is accessed with a dynamic key (e.g.,
obj[variable]), only its direct properties are now protected from mangling. Nested properties that are always accessed with static keys can still be mangled safely.Closes #10332
Test plan
🤖 Generated with Claude Code